package com.richman.view;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Container;
import java.awt.Dimension;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Vector;

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTabbedPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JButton;
import javax.swing.JTextArea;

import com.richman.controller.DecreaseRatioClient;
import com.richman.ps38.entity.BetAdyData;
import com.richman.ps38.entity.BetDvalue;
import com.richman.ps38.entity.Event;
import com.richman.ps38.entity.HGEvent;
import com.richman.ps38.entity.ISNPS38Event;
import com.richman.ps38.entity.ISNHGSendData;
import com.richman.ps38.entity.SendData;
import com.richman.utils.Common;

import java.awt.FlowLayout;
import java.awt.Toolkit;

import javax.swing.BoxLayout;
import java.awt.event.ActionListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.event.ActionEvent;



public class MainWindow extends JFrame {

	/**
	 * 
	 */
	private static final long serialVersionUID = -285041842903797245L;
	
	JLabel status = null;
	
	JLabel hgstatus = null;
	JLabel ps38status = null;
	
	JLabel hgspecialaccountstatus = null;
	
	JLabel hasSpecialIllegalstatus = null;
	
	Vector<String> forbidLeagues = new Vector<String>();
	Vector<String> negLeagues = new Vector<String>();
	
	public MainWindow(){
        intiComponent();
        
        String title = "";
        if(DecreaseRatioClient.useForOriginal==true&&DecreaseRatioClient.bNeg==false) {
			title = "笑傲江湖    v1.0.0";
		}else {
			title = "反投   v1.0.0";
		}
        
        setTitle(title);
        
        
        setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
        
        setIconImage(Toolkit.getDefaultToolkit().getImage("xajh.png"));
        
        addWindowListener(new WindowAdapter() {
    		public void windowClosing(WindowEvent e) {
    			int n = JOptionPane.showConfirmDialog(null, "确认退出吗?", "退出程序",
    					JOptionPane.YES_NO_OPTION);
    			if (n == JOptionPane.YES_OPTION) {					
    				System.exit(0);
    			}else{
    				
    				setVisible(true);
    			}

    		}
    	});
        
        
        
        addKeyListener(new KeyAdapter() {

			@Override

			public void keyPressed(KeyEvent e) {

			super.keyPressed(e);

			char c = e.getKeyChar();

			int code = e.getKeyCode();
			
			String text  = "";
			
			if(eventPane.betCentralPane.isVisible() == true) {
				
				
				if(code == 67) {
					
					text  = "Focus on Main WND你按下的键的信息：keyChar = " + c + " KeyCode = " + code;
					
					eventPane.betCentralPane.showBetWnd();
					
					System.out.println(text);
					
				}
				
				
				
			}

			

			

			}

			});

        setFocusable(true);
//        requestFocus();
        
      
        
        
        
        
        
        jTabbedpane.addKeyListener(new KeyAdapter() {

			@Override

			public void keyPressed(KeyEvent e) {

			super.keyPressed(e);

			char c = e.getKeyChar();

			int code = e.getKeyCode();
			
			String text  = "";
			
			if(code == 67) {
				
				text  = "Focus on out jTabbedpane你按下的键的信息：keyChar = " + c + " KeyCode = " + code;
				
				eventPane.betCentralPane.showBetWnd();
				
				System.out.println(text);
				
			}

			

			

			}

			});

        jTabbedpane.setFocusable(true);
        
        
        
        
	}
	
	
	
	
	
	
	

	private JTabbedPane jTabbedpane = new JTabbedPane();// ���ѡ������  


	SpecialEventWindowPane specialEventPane = new SpecialEventWindowPane();
	
	EventWindowPane eventPane = new EventWindowPane();
	
	AccountWindowPane accountWndPane = new AccountWindowPane();
	
	
	TeamMatchWindowPane teamMatchWindowPane = new TeamMatchWindowPane();
	
	
	
	SettingPane settingPane = new SettingPane();
	
	private JPanel panel = new JPanel();

	JTextArea hgTextArea = null;
	
	JTextArea PS38TextArea = null;
	
	
	JScrollPane scroll = null;
	
	public void setForbidLeagues(Vector<String> forbidLeagues) {
		this.forbidLeagues = forbidLeagues;
	}
	
	public Vector<String> getForbidLeagues(){
		return forbidLeagues;
	}
	
	public void setNegLeagues(Vector<String> negLeagues) {
		this.negLeagues = negLeagues;
	}
	
	public Vector<String> getNegLeagues(){
		return negLeagues;
	}
	
	
	//ps38
	
	public Vector<String[]> getPS38Accounts(){
		return accountWndPane.getPS38Accounts();
	}
	
	//ps38
	
	
	//hg
	
	public Vector<String[]> getHGAccounts() {
		return accountWndPane.getHGAccounts();
	}
	
	//isn
	public Vector<String[]> getISNAccounts(){
		return accountWndPane.getISNAccounts();
	}
	
	
	public int getDanshiMaxTime() {
		return settingPane.getDanshiMaxTime();
	}
	
	public int getDanshiMinTime() {
		return settingPane.getDanshiMinTime();
	}


    private void intiComponent()  
    {  

		final Container container = getContentPane();
		
		container.setLayout(new BorderLayout());
		

		container.add(panel,BorderLayout.NORTH);
		
		
		
		container.add(jTabbedpane, BorderLayout.CENTER);  
		
		panel.setPreferredSize(new Dimension(0, 150));
		
		jTabbedpane.add(eventPane,"赛事");
		
//		if(SpecialServer.useForOriginal==false) {
//			jTabbedpane.add(specialEventPane,"特殊赛事");
//		}else {
//			jTabbedpane.add(specialEventPane,"汇总");
//		}

		//jTabbedpane.add(accountWndPane,"帐号");
		
		
		//jTabbedpane.add(teamMatchWindowPane, "合并球队");
		
		//jTabbedpane.add(settingPane,"设置");
		
		getContentPane().add(panel, BorderLayout.NORTH);
		panel.setLayout(null);
		
		JButton stopButton = new JButton("停止");
		stopButton.setEnabled(false);
		
		status = new JLabel("状态：未连接");
		status.setBounds(1100, 10, 200, 26);
		panel.add(status);
		
		hgstatus = new JLabel("皇冠状态：未登录");
		hgstatus.setBounds(1100, 36, 200, 26);
		//panel.add(hgstatus);
		
		ps38status = new JLabel("平博状态：未登录");
		ps38status.setBounds(1100, 62, 200, 26);
		//panel.add(ps38status);
		
		hgspecialaccountstatus = new JLabel("ISN状态：未登录");
		hgspecialaccountstatus.setBounds(1100, 88, 200, 26);
		//panel.add(hgspecialaccountstatus);
		
		hasSpecialIllegalstatus = new JLabel("特殊投注（非正常投注）:无非正常投注");
		hasSpecialIllegalstatus.setBounds(1100, 114, 400, 26);
	//	panel.add(hasSpecialIllegalstatus);
		
		JButton startButton = new JButton("启动");
		startButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				
				//DaShui.bStartEngine = true;
				DecreaseRatioClient.StartEngine();
				if(DecreaseRatioClient.bStartEngine == true) {
					startButton.setEnabled(false);
					stopButton.setEnabled(true);
					
				}
				
			}
		});
		startButton.setBounds(10, 64, 86, 23);
		//panel.add(startButton);
		

		stopButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				
				DecreaseRatioClient.bStartEngine = false;
				startButton.setEnabled(true);
				stopButton.setEnabled(false);
				
			}
		});
		stopButton.setBounds(126, 64, 86, 23);
		//panel.add(stopButton);
		
		hgTextArea = new JTextArea();
		hgTextArea.setBounds(240, 0, 767, 150);
		hgTextArea.setEditable(false);
		
		
		
		scroll = new JScrollPane(hgTextArea);
		scroll.setBounds(240, 0, 767, 150);
		
		
		panel.add(scroll, null);
		
		
		
		
		
		
		
/*		PS38TextArea = new JTextArea();
		PS38TextArea.setBounds(240, 77, 767, 63);
		panel.add(PS38TextArea);
		PS38TextArea.setEditable(false);*/
		

        setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);  

        setBounds(100, 100, 1660, 900); 

    }
    
    
    public void setWraningBackGround() {
    	
    	this.getContentPane().setBackground(Color.RED);
    	
    //	setBackground(Color.RED);
    	
    }
    
    
    public void updateHGTextArea(String text) {
    	hgTextArea.setText(text);
    	
    	
    	
/*    	hgTextArea.selectAll();
    	if (hgTextArea.getSelectedText() != null) {
    		hgTextArea.setCaretPosition(hgTextArea.getSelectedText().length());
    		hgTextArea.requestFocus();
    	}*/
    	
    	
    }
    
	public void updatePS38TextArea(String text) {
		
		PS38TextArea.setText(text);
	}
	
	public void updateMainWndStatusText(int type, String str) {
		
		if(type == 0) {
			status.setForeground(Color.red);
		}else {
			status.setForeground(Color.BLACK);
		}
		
		status.setText("状态：" + str);
		
	}
	
	
	
	public void updateMainWndHGStatusText(int type, String str) {
		
		if(type == 0) {
			hgstatus.setForeground(Color.red);
		}else {
			hgstatus.setForeground(Color.BLACK);
		}
		
		hgstatus.setText("皇冠状态：" + str);
		
	}

	
	public void updateMainWndSpecialHGStatusText(int type, String str) {
		
		if(type == 0) {
			hgspecialaccountstatus.setForeground(Color.red);
		}else {
			hgspecialaccountstatus.setForeground(Color.BLACK);
		}
		
		hgspecialaccountstatus.setText("ISN状态：" + str);
		
	}
	
	public void updateMainWndSpecialHasIllegalStatusText(int type, String str) {
		
		if(type == 0) {
			hasSpecialIllegalstatus.setForeground(Color.red);
		}else {
			hasSpecialIllegalstatus.setForeground(Color.BLACK);
		}
		
		hasSpecialIllegalstatus.setText("特殊投注（非正常投注）:" + str);
		
	}

	
	public void updateMainWndPS38StatusText(int type, String str) {
		
		if(type == 0) {
			ps38status.setForeground(Color.red);
		}else {
			ps38status.setForeground(Color.BLACK);
		}
		
		ps38status.setText("平博状态：" + str);
		
	}
	
	
    
	public void updateBetDvalueTable(Vector<BetDvalue> betdvalues) {
		specialEventPane.updateBetDvalueTable(betdvalues);
	}
	
	
	public void updateBetDvalueTable1(Vector<BetDvalue> betdvalues) {
		specialEventPane.updateBetDvalueTable1(betdvalues);
	}
	
	
	public void updateBetLimitDvalueTable(Vector<BetDvalue> betdvalues) {
		specialEventPane.updateBetLimitDvalueTable(betdvalues);
	}
	
	

	
	

	public void updateBetCentralTable(Vector<SendData> events, Vector<ISNHGSendData> isnhgsenddatas) {
		
		eventPane.updateBetCentralTable(events, isnhgsenddatas);
	}  
	
	public void updateBrowserAccounts(Vector<String> varAccounts) {
		eventPane.updateBrowserAccounts(varAccounts);
	}
	
	
	public synchronized  void updateBetAdyTable(Vector<String[]> events) {
		
		eventPane.updateBetAdyTable(events);
	}  
	
	public synchronized  void updateProfitTable(Vector<BetAdyData> events) {
		
		eventPane.updateProfitTable(events);
	}  
	
	
	public Vector<BetDvalue> getBetDvalues(){
		return eventPane.getBetDvalues();
	}
	
	public Vector<BetAdyData> getBetAdyDatas(){
		return eventPane.getBetAdyDatas();
	}
	
	
	public void updateBetLogTable(Vector<BetAdyData> betLogDatas) {
		eventPane.updateBetLogTable(betLogDatas);
	}
	
	
	public void updateBetLimitTable(Vector<BetAdyData> betLogDatas) {
		eventPane.updateBetLimitTable(betLogDatas);
	}
	
	
	public void updateHGPS38EventsTable(Vector<String[]> events) {
		
		eventPane.updateHGPS38EventsTable(events);
	}  
	
	
	
	public void updateTeamMatchHGTeams(Vector<HGEvent> hgevents) {
		teamMatchWindowPane.updateTeamMatchHGTeams(hgevents);
	}
	
	
	
	public void updateTeamMatchPS38Teams(Vector<Event> ps38events) {
		teamMatchWindowPane.updateTeamMatchPS38Teams(ps38events);
	}
	
	
	
	public Vector<String[]> getHGPS38TeamsList(){
		return teamMatchWindowPane.getHGPS38TeamsList();
	}
	
	
	public void updateHGAccountStatus(String account, int statusCode) {
		accountWndPane.updateHGAccountStatus(account, statusCode);
	}

	public void updatePS38AccountStatus(String account, int statusCode) {
		accountWndPane.updatePS38AccountStatus(account, statusCode);
		
	}
	
	
	public void updatePS38AccountBalance(String account, String balance) {
		accountWndPane.updatePS38AccountBalance(account, balance);
	}
	
	
	public void updateHGAccountBalance(String account, String balance) {
		accountWndPane.updateHGAccountBalance(account, balance);
	}
	
	public void updateISNAccountBalance(String account, String balance) {
		accountWndPane.updateISNAccountBalance(account, balance);
	}
	
//	public int getUpdateSeconds() {
//		
//		return settingPane.getUpdateSeconds();
//	}
//	
//	
//	public double getsideMinodd() {
//		return settingPane.getsideMin();
//	}
//	
//	public double getsumMinodd() {
//		return settingPane.getsumMin();
//	}
	
	public int gethgPS38RQBetAmount() {
		return settingPane.gethgPS38RQBetAmount();
	}
	
	
	public int gethgPS38DXBetAmount() {
		return settingPane.gethgPS38DXBetAmount();
	}

	public double getps38RQAmount() {
		return settingPane.getps38RQAmount();
	}
	
	public double getps38DXAmount() {
		return settingPane.getps38DXAmount();
	}

	public double getbetodd() {
		
		
		double baseodd = settingPane.getbetodd();
		
		double betodd = baseodd;
		
//		String accounttype = SpecialServer.betCtrMng.getAccounttype();
//		
//		if(accounttype.equals("1")) {
//			betodd = baseodd - 0.03;
//		}else if(accounttype.equals("2")) {
//			betodd = baseodd - 0.01;
//		}else if(accounttype.equals("4")) {
//			betodd = baseodd + 0.01;
//		}
		
		return betodd;
		

	}
	
	public boolean getautobet() {
		return settingPane.getAutoBet();
	}
	
	public boolean getbps38RQBetAmount() {
		return settingPane.getbps38RQBetAmount();
	}
	
	public boolean getbps38DXBetAmount() {
		return settingPane.getbps38DXBetAmount();
	}
	
	public double getps38RQPercent() {
		return settingPane.getps38RQPercent();
	}
	
	public double getps38DXPercent() {
		return settingPane.getps38DXPercent();
	}
	
	public boolean getMatchFilter() {
		return settingPane.getMatchFilter();
	}
	
	public int getReceiveDataInterval() {
		return settingPane.getReceiveDataInterval();
	}

	public int getnotsamematchReceiveDataInterval() {
		return settingPane.getnotsamematchReceiveDataInterval();
	}
	

	public double getsideMinodd() {
		return settingPane.getsideMin();
	}
	


	public boolean getbISNRQBetAmount() {
		return settingPane.isbISNRQBetAmount();
	}
	
	public boolean getbISNDXBetAmount() {
		return settingPane.isbISNDXBetAmount();
	}
	
	public int gethgISNRQBetAmount() {
		return settingPane.getHgISNRQBetAmount();
	}
	
	public double getisnRQAmount() {
		return settingPane.getIsnRQAmount();
	}
	
	public double getisnRQPercent() {
		return settingPane.getIsnRQPercent();
	}

	
	
	public int gethgISNDXBetAmount() {
		return settingPane.getHgISNDXBetAmount();
	}
	
	public double getisnDXAmount() {
		return settingPane.getIsnDXAmount();
	}
	
	public double getisnDXPercent() {
		return settingPane.getIsnDXPercent();
	}
	
	
	
	public double getsumMinodd() {
		
		double baseodd = settingPane.getsumMin();
		
		double sumMinodd = baseodd;
		
		String accounttype = DecreaseRatioClient.betCtrMng.getAccounttype();
		
		if(accounttype.equals("1")) {
			sumMinodd = baseodd - 0.03;
		}else if(accounttype.equals("2")) {
			sumMinodd = baseodd - 0.01;
		}else if(accounttype.equals("4")) {
			sumMinodd = baseodd + 0.01;
		}
		
		return sumMinodd;
		
		
	}
	
	
	
	public double getCtypesumMinodd() {
		
		return settingPane.getsumMin();
		
		
		
		
	}
	
	
	
	public double getsideMaxodd() {
		return settingPane.getsideMax();
	}
	
	
	public double getsumMaxodd() {
		return settingPane.getsumMax();
	}
	
	
	public boolean getBetHalf() {
	
		return settingPane.getBetHalf();
		
	}
	
	
	
	public boolean getBetWhole() {
		return settingPane.getBetWhole();
	}
	
	
	public boolean getIgnoreWarn() {
		return settingPane.getIgnoreWarn();
		
	}
	
	
	public boolean getBetDown() {
		return settingPane.getBetDown();
		
	}
	
	public int getRebetTime() {
		return settingPane.getrebettime();
	}
	
	public int getdelaybettime() {
		return settingPane.getdelaybettime();
	}
	
	
	public int getrefreshdelaybettime() {
		return settingPane.getrefreshdelaybettime();
	}
	
	public int getbetlimit() {
		return settingPane.getbetcountLimit();
	}
	
	public int getstartBetGold() {
		return settingPane.getstartBetGold();
	}
	
	public int getstartBetGoldHg() {
		return settingPane.getstartBetGoldHg();
	}
	
	public int getDxStartBetGoldHg() {
		return settingPane.getDxStartBetGoldHg();
	}
	
	public int gethgmaxbet() {
		return settingPane.gethgmaxbet();
	}
	
	public int getforbidst(){
		return settingPane.getforbidst();
	}
	
	public int getforbided(){
		return settingPane.getforbided();
	}
	
	public boolean getbetdanshi() {
		return settingPane.getbetdanshi();
	}
	
	public boolean getbetrunning() {
		return settingPane.getbetrunning();
	}
	
	public boolean getbetpankou() {
		return settingPane.getbetpankou();
	}
	
	public boolean getbetdq() {
		return settingPane.getbetdq();
	}
	
	public boolean getbetxq() {
		return settingPane.getbetxq();
	}
	
	
	public int getmanualBetSuccessTime() {
		return settingPane.getmanualBetSuccessTime();
	}
	
	
	public double getmaxdvalue() {
		return settingPane.getmaxdvalue();
	}
	
	public int getdvaluelimit() {
		return settingPane.getdvaluelimit();
	}
	
	public int getemailRQDvalue() {
		return settingPane.getemailRQDvalue();
	}
	
	public int getemailDQDvalue() {
		return settingPane.getemailDQDvalue();
	}
	
	public int getemailXQDvalue() {
		return settingPane.getemailXQDvalue();
	}
	
	public int getbeforeGameTimeFilter()
	{
		return settingPane.getbeforeGameTimeFilter();
	}
	
	public int getBetDownGold() {
		return settingPane.getBetDownGold();
	}
	
	public double getSpecialMinRatio() {
		return settingPane.getSpecialMinRatio();
	}

	public double getSpecialSecondMinRatio() {
		return settingPane.getSpecialSecondMinRatio();
	}
	
	public double getSpecialDXQMinRatio() {
		return settingPane.getSpecialDXQMinRatio();
	}

	
	public int getSpecialBetAmount() {
		return settingPane.getSpecialBetAmount();
	}
	
	public int getSpecialSecondBetAmount() {
		return settingPane.getSpecialSecondBetAmount();
	}
	
	public int getSpecialDXQBetAmount() {
		return settingPane.getSpecialDXQBetAmount();
	}

	public int getspecialBetInterval() {
		return settingPane.getspecialBetInterval();
	}
	
	public int getspecialDXQMinBet() {
		return settingPane.getspecialDXQMinBet();
	}

	public void updateSpecialBetAdyTable(Vector<BetAdyData> specialBetAdyDatas) {
		specialEventPane.updateSpecialBetAdyTable(specialBetAdyDatas);
	}
	
	
	public void updateSpecialBetLogTable(Vector<BetAdyData> specialBetLogDatas) {
		specialEventPane.updateSpecialBetLogTable(specialBetLogDatas);
	}

	public double getLimitPercent() {
		return settingPane.getLimitPercent();
	}

}

